package com.steel.yfmall.cloud.assistant.controller;

import com.alibaba.fastjson.JSON;
import com.steel.yfmall.cloud.assistant.api.stock.ZgOrderService;
import com.steel.yfmall.cloud.assistant.bean.param.ZgOrderParamBean;
import com.steel.yfmall.cloud.assistant.bean.param.zg.APIParaWarrantyBean;
import com.steel.yfmall.cloud.assistant.bean.result.*;
import com.steel.yfmall.cloud.components.utils.base.APIMsgBean;
import com.steel.yfmall.cloud.components.utils.base.Pages;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 龙飞
 * @version 1.0
 * @since 2020/12/18 星期五 13:47
 */

@RestController
@Slf4j
public class ZgOrderController {

    /**
     * 合同预览
     *
     * @param zgOrderParamBean 订单号	masterOrderSn
     * @return
     */
    @RequestMapping(value = "orderShowPdf")
    public APIMsgBean<ContractInfoBean> orderShowPdf(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function createPushOrder :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.orderShowPdf(zgOrderParamBean);
    }

    /**
     * SO01-订单建立
     *
     * @param zgOrderParamBean 订单号	orderNo
     * @return
     */
    @RequestMapping(value = "createPushOrder")
    public APIMsgBean<ContractInfoBean> createPushOrder(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function createPushOrder :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.createPushOrder(zgOrderParamBean);
    }

    /**
     * SO03-订单确认通知
     *
     * @param zgOrderParamBean 调用参数  内含操作人和订单号
     * @return
     */
    @RequestMapping("addZgOrderConfirm")
    public APIMsgBean<Boolean> addZgOrderConfirm(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function addZgOrderConfirm :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.addZgOrderConfirm(zgOrderParamBean);
    }

    /**
     * 取消订单
     *
     * @param zgOrderParamBean 调用参数  内含操作人和订单号
     * @return
     */
    @RequestMapping("cannotZgOrder")
    public APIMsgBean<Boolean> cannotZgOrder(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function cannotZgOrder :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.cannotZgOrder(zgOrderParamBean);
    }

//    /**
//     * 删除订单
//     *
//     * @param zgOrderParamBean 调用参数  内含订单号
//     * @return
//     */
//    @RequestMapping("deleteZgOrder")
//    public APIMsgBean<Boolean> deleteZgOrder(@RequestBody ZgOrderParamBean zgOrderParamBean) {
//        if (log.isDebugEnabled()) {
//            log.info("function deldeteZgOrder :" + JSON.toJSONString(zgOrderParamBean));
//        }
//        return zgOrderService.deleteZgOrder(zgOrderParamBean);
//    }

    /**
     * 通过订单号与客户编号，查询结算结果
     *
     * @param zgOrderParamBean 订单合同号	orderNo
     *                         客户编号		custNO
     * @return
     */
    @RequestMapping("SSKEC007")
    public APIMsgBean<SSKEC007Bean> SSKEC007(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function SSKEC007 :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.SSKEC007(zgOrderParamBean);
    }

    /**
     * SO12-打印订单合同模板
     *
     * @param zgOrderParamBean 订单号	orderNo
     * @return
     */
    @RequestMapping("saveContractAddress")
    public APIMsgBean<ContractAddressBean> saveContractAddress(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function saveContractAddress :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.saveContractAddress(zgOrderParamBean);
    }

    /**
     * 通过订单号获取应付单
     * 获取整理 AV05 进行展示。仅 返回 电商单 数据。
     *
     * @param zgOrderParamBean 拼接后的合同号-orderNos
     * @return AV05（应收凭证）的集合
     */
    @RequestMapping(value = "getCanInvoiceListByOrderNo")
    public APIMsgBean<AVSystemInterfaceResultBean> getCanInvoiceListByOrderNo(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function getCanInvoiceListByOrderNo :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.getCanInvoiceListByOrderNo(zgOrderParamBean);
    }

    /**
     * 设置开明细票OR汇总票
     *
     * @param zgOrderParamBean 账套别		compId
     *                         应收凭单号	arNos
     *                         明细or汇总	detailOrSum		D为明细/S为汇总
     * @return
     */
    @RequestMapping(value = "setDetailOrSumData")
    public APIMsgBean<AVSystemInterfaceResultBean> setDetailOrSumData(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function setDetailOrSumData :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.setDetailOrSumData(zgOrderParamBean);
    }

    /**
     * 申请确认
     *
     * @param zgOrderParamBean 应收凭单号	ARNOQRY
     *                         账套别	COMPIDQRY
     *                         发票类型	MERGEQRY
     * @return
     */
    @RequestMapping(value = "applyInvoiceOk")
    public APIMsgBean<AVSystemInterfaceResultBean> applyInvoiceOk(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function applyInvoiceOk :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.applyInvoiceOk(zgOrderParamBean);
    }

    /**
     * 开票接口整合
     *
     * @param zgOrderParamBean 订单号	orderNo
     * @return
     */
    @RequestMapping(value = "issueInvoice")
    public APIMsgBean<AVSystemInterfaceResultBean> issueInvoice(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function issueInvoice :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.issueInvoice(zgOrderParamBean);
    }


    /**
     * AR03-查询运费余额
     *
     * @param zgOrderParamBean 客户编号	CUSTNO
     *                         运费担当	TRANSWAY
     * @return 是否查询成功    ISSUCCESS
     * 客户编号	custNo
     * 客户中文名称	custName
     * 日期时间戳印	timestamp
     * 结果总共几笔资料	total
     * 运费余额	result
     * 结果讯息	msg
     */
    @RequestMapping(value = "searchFreightBalance")
    public APIMsgBean<FreightBalanceBean> searchFreightBalance(@RequestBody ZgOrderParamBean zgOrderParamBean) {
        if (log.isDebugEnabled()) {
            log.info("function searchFreightBalance :" + JSON.toJSONString(zgOrderParamBean));
        }
        return zgOrderService.searchFreightBalance(zgOrderParamBean);
    }

    /**
     * 获取质保书信息
     * @Title: getWarrantyFromZg
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param apiParaBean 参数说明
     * @return com.steel.yfmall.cloud.components.utils.base.APIMsgBean<com.steel.yfmall.cloud.components.utils.base.Pages<com.steel.yfmall.cloud.assistant.bean.result.APIResultWarrantyBean>>    返回类型
     * @author yuchaohua
     * @date 2021/2/20 15:06
     */
    @RequestMapping(value = "getWarrantyFromZg")
    public APIMsgBean<Pages<APIResultWarrantyBean>> getWarrantyFromZg(@RequestBody APIParaWarrantyBean apiParaBean){
        if (log.isDebugEnabled()) {
            log.info("function getWarrantyFromZg :" + JSON.toJSONString(apiParaBean));
        }
        return zgOrderService.getWarrantyFromZg(apiParaBean);
    }

    @Autowired
    private ZgOrderService zgOrderService;
}
